#include "fsmManager.h"
#include "state.h"

void CFSMManager::Init(ICharacter* owner)
{
	_owner = owner;

	_prevState = nullptr;
	_currState = nullptr;
//	_globalState = nullptr;
}

void CFSMManager::Update()
{
	//if(_globalState)
	//	_globalState->Execute(_owner);

	if(_currState)
		_currState->Execute(_owner);
}

void CFSMManager::ChangeState(IState* newState)
{
	if(nullptr == newState) return;

	_beginstate.Reset();
	_prevState = _currState;

	if(_currState)
		_currState->Exit(_owner);

	_currState = newState;
	
	_currState->Enter(_owner);
}

//void CFSMManager::ChangeGlobalState(IState* newGState)
//{
//	if(nullptr == newGState) return;
//
//	if(_globalState)
//		_globalState->Exit(_owner);
//	_globalState = newGState;
//	if(_globalState)
//		_globalState->Enter(_owner);
//}

void CFSMManager::RevertToPreviousState()
{
	ChangeState(_prevState);
}